<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 * `id` INT NOT NULL AUTO_INCREMENT ,
  `nomtype` VARCHAR(45)NOT NULL ,
  `modele` VARCHAR(45) NULL ,
 */

/**
 * Description of TypeArticle
 *
 * @author Gael
 */
class TypeArticle {
    public $id;
    public $nomType;
    public $modele;
    
    function __construct($id, $nomType, $modele) {
        $this->id = $id;
        $this->nomType = $nomType;
        $this->modele = $modele;
    }

    public function getId() {
        return $this->id;
    }

    public function setId($id) {
        $this->id = $id;
    }

    public function getNomType() {
        return $this->nomType;
    }

    public function setNomType($nomType) {
        $this->nomType = $nomType;
    }

    public function getModele() {
        return $this->modele;
    }

    public function setModele($modele) {
        $this->modele = $modele;
    }

    static public function byId($id){
        try{
            $db= getPdo();
            $rep = $db->query("select * from typearticle where id=$id" );
            while($data =$rep->fetch()){
                $ta= new TypeArticle($id, $data['nomtype'], $data['modele']);
            }
            
            $rep->closeCursor();
            return $ta;
        }catch(Exception $e){
            die('erreur requete'.$e->getMessage());
            return false;
        }
    }
    static public function all(){
        try{
            $db= getPdo();
            $tab = array();
            
            $rep = $db->query("select * from typearticle  " );
            while($data =$rep->fetch()){
                $tab[$data['id']    ]=new TypeArticle($data['id'], $data['nomtype'], $data['modele']);
                
            }
            $rep->closeCursor();
            return $tab;
        }catch(Exception $e){
            die('erreur requete'.$e->getMessage());
        }
    } 
   
}



?>
